package cn.jjzd.info.service;

import cn.jjzd.info.response.ArticlePageResponse;
import cn.jjzd.info.client.ArticleClient;
import cn.jjzd.info.client.CategoryClient;
import cn.jjzd.info.pojo.Article;
import cn.jjzd.info.pojo.Category;
import org.apache.commons.lang.time.DateFormatUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class InfoService {
    @Autowired
    private ArticleClient sysArticleClient;

    @Autowired
    private CategoryClient sysCategoryClient;

   /* public Map<String,List<SysArticleBo>> queryArticleListByCids(List<Long> cids){
        return this.sysArticleClient.queryArticleListByCids(cids);
    }*/

    public Map<String,Object> loadDetailData(Long id){
        Article sysArticle = this.sysArticleClient.queryById(id);
        ArticlePageResponse articlePageBo = new ArticlePageResponse();
        BeanUtils.copyProperties(sysArticle,articlePageBo);
        articlePageBo.setCreateDateStr("发布时间:"+ DateFormatUtils.format(sysArticle.getCreateDate(),"yyyy-MM-dd HH:mm"));
        Map<String,Object> map = new HashMap<>();
        List<Category> categories = this.sysCategoryClient.queryByCid(sysArticle.getCategoryId());

        List<Category> lastCategories = this.sysCategoryClient.queryCategoryList(sysArticle.getCategoryId());
        map.put("categories",categories);
        map.put("lastCategories",lastCategories);
        map.put("articled",articlePageBo);
        return map;
    }

    public Map<String,Object> loadMoreData(Long cid){
        List<Category> categories = this.sysCategoryClient.queryByCid(cid);
        List<Category> lastCategories = sysCategoryClient.queryCategoryList(cid);
        Map<String,Object> map = new HashMap<>();
        map.put("cid",cid);
        map.put("categories",categories);
        map.put("lastCategories",lastCategories);

        return map;
    }

}
